class Solution {
public:
    int maxTurbulenceSize(vector<int>& nums) {
        int size = nums.size();
        if (size == 1)return 1;
        int ret = 0;
        vector<int> dp_1(size, 1);
        vector<int> dp_2(size, 1);
        for (int i = 1; i < size; i++) {
            if (nums[i] - nums[i - 1] > 0) {
                dp_1[i] = dp_2[i - 1] + 1;
                dp_2[i] = 1;
            }
            else if (nums[i] - nums[i - 1] < 0) {
                dp_2[i] = dp_1[i - 1] + 1;
                dp_1[i] = 1;
            }
            ret = max(max(dp_1[i], dp_2[i]), ret);
        }
        return ret;
    }
};